import { printA4, excelTablesExport } from '@vimi/utils-tool'

/**
id: 开始到处的dom id
name: 导出的excel 名称
**/
export function exportToExcel(id, name) {
  return excelTablesExport(id, name, {
    emptyRows: 1,
    styles: {
      // 全局样式
      border: {
        left: { style: 'thin' },
        top: { style: 'thin' },
        right: { style: 'thin' },
        bottom: { style: 'thin' },
      },
      alignment: {
        vertical: 'center',
        horizontal: 'center',
        wrapText: true,
      },
    },
    // 单元格样式，最顶级设置(styles -> dataset -> cellStyles)
    // 可以设置成 A1，或 'r-c' 的主键
    cellStyles: {
      A1: { border: {} },
      B1: { border: {} },
      C1: { border: {} },
      '0-3': { border: {} },
      '0-4': { border: {} },
      '0-5': { border: {} },
      '0-6': { border: {} },
      '0-7': { border: {} },
      '0-8': { border: {} },
      '0-9': { border: {} },
      '0-10': { border: {} },
      A2: { border: {}, horizontal: 'right' },
      B2: { border: {}, horizontal: 'right' },
      C2: { border: {}, horizontal: 'right' },
      '1-3': { border: {}, horizontal: 'right' },
      '1-4': { border: {}, horizontal: 'right' },
      '1-5': { border: {}, horizontal: 'right' },
      '1-6': { border: {}, horizontal: 'right' },
      '1-7': { border: {}, horizontal: 'right' },
      '1-8': { border: {}, horizontal: 'right' },
      '1-9': { border: {}, horizontal: 'right' },
      '1-10': { border: {}, horizontal: 'right' },
    },
  })
}

export function printPage(printId) {
  printA4(
    document.getElementById(printId).innerHTML,
    `
    .report-title {text-align: center;margin-bottom: 1rem;font-weight: bold;font-size: 1.5rem;line-height: 1.5;}
    .report-main {margin-bottom: 1rem;margin: 0 auto;padding: 2rem;}
    .table-bordered td {border-color: #333 !important;padding: 0.25rem;text-align: center;vertical-align: middle;}
    .table-bordered {outline: 2px solid #333;}
    .td-text-left {text-align: left !important;text-indent: 2rem;}
  `
  )
}

export const getResultData = res => {
  return (res && res.data && res.data.length && res.data[0]) || {}
}
export const getResultArray = res => {
  return (res && res.data) || []
}
